<?php
include_once "../header1.php";
?>
<script type="text/javascript">
function getHttpRequest()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}
function showHint(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("List").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("List").innerHTML=xmlhttp.responseText;
    }
  }
   var sch_id=document.forms["form1"]["sch_id"].value;
  str=str+","+sch_id;
xmlhttp.open("GET","upp_tea_names.php?q="+str,true);
xmlhttp.send();
}
function fill(val)
{
document.form1.TeaName.value=val;
document.getElementById("List").innerHTML="";
var xmlhttp;    
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
   document.getElementById("TID").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","tra_ids.php?q="+val,true);
xmlhttp.send();
}
</script>
<link rel="stylesheet" href="../css/datepicker.css" type="text/css" />
    <link rel="stylesheet" media="screen" type="text/css" href="../css/layout.css" />
  	<script type="text/javascript" src="../js/jquery.js"></script>
	<script type="text/javascript" src="../js/datepicker.js"></script>
    <script type="text/javascript" src="../js/eye.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/layout.js?ver=1.0.2"></script>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
     else
   {
   date_default_timezone_set("Europe/Paris");
    $t_d=date("Y-m-d");
   if(isset($_POST['SaveChanges']))
   {
$T_NIC_Number=$_SESSION['T_NIC_Number'];
   if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
    $getthsch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$T_NIC_Number."'"); 
   if($roSch=mysql_fetch_array($getthsch))
   {
$Sch_Id=$roSch['School_Id'];   
   if($Sch_Id==$Own_School_Id)
	{
	require_once 'upp.php';
	}
	else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
  }
  else
   {
   $_SESSION['errornotallo']="This person's record is not registered into Teacher's record!";
   }
   }
   }
    else if($_SESSION['Access_Type']=="Administrator")
{
    require_once 'upp.php';
   }
   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
   }
		$T_NIC_Number="";
	   $Training_Id="";
   if(isset($_POST['Edit_This']))
	   {	
		    $Training_Name=$_POST['Training_Name'];
	   	  $resultnet=mysql_query("SELECT * FROM training WHERE Training_Name='$Training_Name'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Training_Id=$rownet['Training_Id'];
}
	  
	  $TeaName=$_POST['TeaName'];
$name=explode(" ",$TeaName);
$fn=$name[0];
$ln=$name[1];
$results= mysql_query("SELECT * FROM teacher Where First_Name='$fn' AND Last_Name='$ln'");
if($row = mysql_fetch_array($results))
{
 $T_NIC_Number=$row['T_NIC_Number'];
}
	  $_SESSION['Training_Id']=$Training_Id;
		$_SESSION['T_NIC_Number']=$T_NIC_Number;
	
 if($TeaName==""||$Training_Name=="Select One")
	   {
		 $_SESSION['errorin1']="Please select the Training name and Teacher's name!";
}
	   else
	   {
	    if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
    $getthsch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'"); 
   if($roSch=mysql_fetch_array($getthsch))
   {
$Sch_Id=$roSch['School_Id'];   
   if($Sch_Id==$Own_School_Id)
	{
	$result=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
	   if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	}
	else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
	}
	else
   {
   $_SESSION['errornotallo']="This person's record is not registered into Teacher's record!";
   }
	}
	 else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
$result=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
	   if(mysql_num_rows($result)==0)
   {
$_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
   }
   }
	 }  
   ?>
    <?php

include_once "../header2.php";


?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
	  <div id="lefttablereg">
<form action="#" method="POST" name="form1">
  <table width="562" border="0" class="tablefontv">
    <tr>
      <td colspan="5"  scope="row" class="err"><?php
		if(isset($_POST['Edit_This'])||isset($_POST['SaveChanges']))
{
 if(isset($_SESSION['error']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errorin']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['errorin1']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin1'];
		unset($_SESSION['errorin1']);
	}
	if(isset($_SESSION['errornorow']))
	{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
			if(isset($_SESSION['errornotallo']))
{
	echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errornotallo'];
unset($_SESSION['errornotallo']);
}
}
		?>
		</td>
      </tr>
    <tr>
      <th width="22" height="25"  scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <td width="154"  scope="row" bgcolor="#6AB5FF">Teacher's Name:</td>
      <td width="140" bgcolor="#999999">
        <?php
 $hin=$_SESSION['NIC_Number'].",".$_SESSION['Access_Type'];
		   echo "<input type='hidden' size='1' id='sch_id' name='sch_id' value='$hin'/>";
	  if(!isset($TeaName))
	{
	   $tnam=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Numberc'");
	  if($rot=mysql_fetch_array($tnam))
	  {
	  $TeaName=$rot['First_Name']." ".$rot['Last_Name'];
	  }
	  }	
	  echo "<input type='text' id='TeaName' name='TeaName' onKeyUp='showHint(this.value)' value='$TeaName' onClick='cleartbox()' size='35'/>";
	  ?></td>
      <td width="101" bgcolor="#6AB5FF">&nbsp;</td>
      <td width="123">&nbsp;</td>
    </tr>
    <tr>
      <th height="26" scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <td scope="row" bgcolor="#6AB5FF">Training Name:</td>
      <td  bgcolor="#999999"><div id="TID"><select name="Training_Name">
        <?php
	  if(isset($_POST['SaveChanges']))
	  {
	   $resultnet=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Idc'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Training_Name=$rownet['Training_Name'];
}
	 echo '<option value="'.$Training_Name.'">'.$Training_Name.'</option>';
	 	  }
	  if(isset($_POST['Edit_This']))
	  {
	   $resultnet=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Training_Name=$rownet['Training_Name'];
}
	 echo '<option value="'.$Training_Name.'">'.$Training_Name.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  
	   if($T_NIC_Number!="")
	  {
	  $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM resource_team WHERE T_NIC_Number='$T_NIC_Number'");
	  }
	  if($T_NIC_Number=="")
	  {
	  $exa=mysql_query("SELECT DISTINCT(Training_Id) FROM resource_team");
	  }
 while($row=mysql_fetch_array($exa))
  {
	 $Tra_Id=$row['Training_Id'];
	 $resultnet=mysql_query("SELECT * FROM training WHERE Training_Id='$Tra_Id'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Tra_Name=$rownet['Training_Name'];
}
	if($Training_Name!=$Tra_Name)
{
	  echo '<option value="'.$Tra_Name.'">'.$Tra_Name.'</option>';
  }
  }
	  ?>
      </select></div></td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <th height="30" scope="row" bgcolor="#6AB5FF">&nbsp;</th>
      <td colspan="2" bgcolor="#6AB5FF" scope="row">
        <a href="Updaterest.php" class="reset">Reset</a>|
        <input name="Edit_This" align="middle" type="submit" value="Edit this" class="buttonok"/>
      </td>
      <td bgcolor="#6AB5FF">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <br/>
  
</form>
<form action="#" method="POST">
    <?php 
	if(isset($_POST['Edit_This']))
	   {
	   if($TeaName!=""&&$Training_Name!="Select One")
	   {
	    if($_SESSION['Access_Type']=="Teacher in Charge")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
    $getthsch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'"); 
   if($roSch=mysql_fetch_array($getthsch))
   {
$Sch_Id=$roSch['School_Id'];   
   if($Sch_Id==$Own_School_Id)
	{
	 $result=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
  echo '<table width="354" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
  {
    
	$Training_Id=$row['Training_Id'];
	$Member_Id=$row['Member_Id'];
	$T_NIC_Number=$row['T_NIC_Number'];
	$From_Date=$row['From_Date'];
	
   ?>
   <?php
      echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "Training Id:";
		echo '</th>';
        echo '<td width="144">';
		echo "<input type='text' name='Training_Idc' value='$Training_Id'/>";
		echo '</td>';
      echo '</tr>';
	  
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Member Id:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Member_Idc' value='$Member_Id'/>";
		echo '</td>';
      echo '</tr>';
	  
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Teachers NIC Number:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='T_NIC_Numberc' value='$T_NIC_Number'/>";
		echo '</td>';
		 echo '</tr>';
		 
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Start Date Of Resource Team:";
		echo '</th>';
       echo '<td>';
	  	   if(isset($_POST['Edit_This']))
{
	   echo "<input type='text' name='From_Datec' value='$From_Date' class='inputDate' id='inputDate'/>";
	   }
	   else
	   {
	   echo "<input type='text' name='From_Datec' value='$t_d' class='inputDate' id='inputDate'/>";
	   }
	   echo '</td>';
      echo '</tr>';
	  
	 }
   echo '</table>';
   
   echo "</br>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" class="buttonok"/>';
	}
	}
	}
	}
	else if($_SESSION['Access_Type']=="Administrator")
{
   $result=mysql_query("SELECT * FROM resource_team WHERE T_NIC_Number='$T_NIC_Number' AND Training_Id='$Training_Id'");
  echo '<table width="354" border="0" class="tablefontv">';
 while($row=mysql_fetch_array($result))
  {
    
	$Training_Id=$row['Training_Id'];
	$Member_Id=$row['Member_Id'];
	$T_NIC_Number=$row['T_NIC_Number'];
	$From_Date=$row['From_Date'];
	
   ?>
   <?php
      echo '<tr>';
        echo '<th width="200" height="44" scope="row">';
		echo "Training Id:";
		echo '</th>';
        echo '<td width="144">';
		echo "<input type='text' name='Training_Idc' value='$Training_Id'/>";
		echo '</td>';
      echo '</tr>';
	  
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Member Id:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='Member_Idc' value='$Member_Id'/>";
		echo '</td>';
      echo '</tr>';
	  
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Teachers NIC Number:";
		echo '</th>';
        echo '<td>';
		echo "<input type='text' name='T_NIC_Numberc' value='$T_NIC_Number'/>";
		echo '</td>';
		 echo '</tr>';
		 
      echo '<tr>';
        echo '<th height="44" scope="row">';
		echo "Start Date Of Resource Team:";
		echo '</th>';
       echo '<td>';
		   if(isset($_POST['Edit_This']))
{
	   echo "<input type='text' name='From_Datec' value='$From_Date' class='inputDate' id='inputDate'/>";
	   }
	   else
	   {
	   echo "<input type='text' name='From_Datec' value='$t_d' class='inputDate' id='inputDate'/>";
	   }
	   echo '</td>';
      echo '</tr>';
	  
	 }
   echo '</table>';
   
   echo "</br>";
   echo '<input name="SaveChanges" align="middle" type="submit" value="Save changes" class="buttonok"/>';
 }
 }
	   }
	   ?>
       </form>
 </div>
 <div id="righttablereg">
  <div class="suggestionListsch" id="List"></div>
 </div>  
</div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">RESOURCE TEAM</h2>
            </div>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php
}
?>
</body>
</html>